<template>
    <div class="my-templates">
        <div class="my-main">
            <div class="my-item" v-for="(item, index) in list" :key="index">
                <div class="my-img">
                    <a-image class="image" :src="item.templateImgeUrl" v-if="item.templateImgeUrl" />
                    <div class="img-err" v-else>
                        <FundOutlined />
                    </div>
                    <div class="my-icon">
                        <a-button type="primary" :size="'small'" @click="handleEdit(item)">
                            <template #icon>
                                <EditOutlined />
                            </template>
                        </a-button>
                        <a-button type="primary" :size="'small'" @click="handCopy(item)">
                            <template #icon>
                                <CopyOutlined />
                            </template>
                        </a-button>
                    </div>
                </div>
                <div class="my-title">{{ item.templateName }}</div>
                <div class="my-tag">
                    <div>
                        <a-tag color="red">{{ item.tagColourName }}</a-tag>
                        <a-tag color="red">{{ item.tagRatioName }}</a-tag>
                    </div>

                    <span>{{ item.templateCode }}</span>
                </div>

                <div class="my-edit">
                    <div class="my-edit-text">
                        <span>关联模板</span>
                        <!-- <span class="my-edit-num">{{ item.templateRelevance }}</span> -->
                        <span class="my-edit-num">{{
                            item.templateRelevance ? item.templateGroup.length + item.templateRelevance.length : 0
                        }}</span>
                        <EditOutlined class="my-icon" @click.stop="relevanceFun(item)" />
                    </div>
                    <EyeOutlined @click="previewFun(item)" class="my-icon" />
                </div>
            </div>
        </div>
        <!-- <a-pagination
            size="small"
            :total="pagination.total"
            show-size-changer
            show-quick-jumper
            :show-total="(total) => `共 ${pagination.total} 条`"
        /> -->
        <!-- <a-pagination size="small" :total="pagination.total" show-less-items /> -->
        <a-pagination v-model:current="total" :total="pagination.total" show-less-items @change="handleTableChange" />
        <relevanceModel
            v-if="relevanceModl"
            :visible="relevanceModl"
            :title="relevanceTitle"
            :templateCode="templateCode"
            :templateName="templateName"
            :tagColourName="tagColourName"
            :relationTemplateCode="relationTemplateCode"
            :type="relevanceType"
            :templateList="templateList"
            @submit="handleSubmit"
        ></relevanceModel>
        <copyModel
            v-if="copyModl"
            :visible="copyModl"
            :title="copyTitle"
            :templateCode="copytemplateCode"
            :templateName="copytemplateName"
            :type="relevanceType"
            :templateList="templateList"
            @submit="handleSubmit"
        ></copyModel>
        <viewModel
            v-if="viewModl"
            :visible="viewModl"
            :templateCode="viewTemplateCode"
            :title="viewTitle"
            @submit="handleviewSubmit"
        ></viewModel>
    </div>
</template>

<script lang="ts">
import { defineComponent, reactive, toRefs, ref, onMounted, computed, createVNode } from 'vue';
import { useI18n } from 'vue-i18n';
import { PaginationQuery } from '@/types/table';
import { FundOutlined, CopyOutlined, EyeOutlined, AppstoreOutlined, UnorderedListOutlined } from '@ant-design/icons-vue';
import { message, Modal } from 'ant-design-vue';
import { addModel, editModel } from '@/api/warehouse';
import { TableState, CheckAble } from '@/types/table';
import relevanceModel from '../relevanceModel.vue';
import copyModel from '../copyModel.vue';
import viewModel from '../viewModel.vue';
export default defineComponent({
    name: 'department',
    components: {
        CopyOutlined,
        FundOutlined,
        EyeOutlined,
        AppstoreOutlined,
        UnorderedListOutlined,
        relevanceModel,
        copyModel,
        viewModel,
    },
    props: {
        list: {
            type: Array,
            default: () => [],
        },
        pagination: {
            type: Object,
            default: () => {},
        },
        tableQuery: {
            type: Object,
            default: () => {},
        },
    },
    setup(props, { emit }) {
        const { t } = useI18n();
        // 角色信息
        const total = computed(() => props.tableQuery.page + 1);
        const state = reactive({
            relevanceType: '',
            templateCode: '',
            templateName: '',
            relevanceTitle: t('yl.tmpModelTitle'),
            relevanceModl: false,
            relationTemplateCode: '',
            templateList: [],
            tagColourName: '',
        });
        const copy = reactive({
            copyType: '',
            copytemplateCode: '',
            copytemplateName: '',
            copyTitle: t('yl.tmpcopyModlTitle'),
            copyModl: false,
            copytemplateList: [],
        });
        const preview = reactive({
            viewTitle: t('yl.tmpPreview'),
            viewModl: false,
            viewTemplateCode: '',
        });
        // 页码改变
        const handleTableChange = (page: any, pageSize: any) => {
            emit('handleTableChange', page);
        };
        const handleEdit = (item: any) => {
            emit('handleEdit', item.templateCode);
        };
        const relevanceFun = (item: any) => {
            console.log(item);
            state.templateCode = item.templateCode;
            state.templateName = item.templateName;
            state.tagColourName = item.tagColourName;
            state.relationTemplateCode =
                item.templateGroup && item.templateGroup.length ? item.templateGroup[0].templateCode : '         ';
            state.templateList = item.templateRelevance;
            state.relevanceModl = true;
        };
        const handleSubmit = (type: string) => {
            if (type == 'submit') {
                state.relevanceModl = false;

                emit('handRelation');
            } else {
                state.relevanceModl = false;
            }
        };

        const handCopy = (item: any) => {
            // copy.copytemplateCode = item.templateCode;
            // copy.copytemplateName = item.templateName;
            // copy.copyModl = true;

            emit('handCopy', item.templateCode);
        };
        // 预览
        const previewFun = (item: any) => {
            console.log(item);
            preview.viewTemplateCode = item.templateCode;
            preview.viewModl = true;
        };
        // 预览弹窗关闭
        const handleviewSubmit = () => {
            preview.viewModl = false;
        };
        return {
            t,
            handleTableChange,
            handleEdit,
            relevanceFun,
            total,
            ...toRefs(state),
            ...toRefs(copy),
            ...toRefs(preview),
            handleSubmit,
            handCopy,
            previewFun,
            handleviewSubmit,
        };
    },
});
</script>

<style lang="scss" scoped>
.my-head {
    width: 100%;
    display: flex;
    justify-content: space-between;
    .head-btn {
        display: flex;
        .head-tab {
            margin-right: 10px;
            display: flex;
            text-align: center;
            line-height: 28px;
            cursor: pointer;
            > span {
                display: block;
                height: 28px;
                width: 32px;
                font-size: 20px;
                border: 1px solid #ccc;
            }
            .head-tab-active {
                color: #ff6702;
            }
            .nonebr {
                border-left: none;
            }
        }
    }
}
.my-main {
    width: 100%;
    display: flex;

    flex-direction: row;
    flex-wrap: wrap;
    .my-item {
        width: 18%;
        margin: 1%;
        height: 290px;
        padding: 15px;
        box-sizing: border-box;
        border: 1px solid #ccc;
        .my-img {
            width: 100%;
            position: relative;
            .img-err {
                width: 100%;
                background: #f4f4f4;
                height: 153px;
                text-align: center;
                line-height: 153px;
                font-size: 30px;
                color: #ccc;
            }
            .my-icon {
                position: absolute;
                top: 10px;
                right: 15px;
                > button {
                    margin-left: 5px;
                }
            }
        }
        .my-title {
            font-size: 16px;
            margin-top: 16px;
        }
        .my-tag,
        .my-edit {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .my-edit {
            border-top: 1px solid #f2f2f2;
            margin-top: 10px;
            padding: 12px 0;
            .my-edit-text {
                font-size: 14px;
                .my-edit-num {
                    display: inline-block;
                    width: 20px;
                    height: 20px;
                    line-height: 20px;
                    text-align: center;
                    border-radius: 10px;
                    background: #ff6702;
                    color: #fff;
                }
            }
            .my-icon {
                font-size: 16px;
            }
        }
    }
}
</style>
<style>
.ant-image-img,
.ant-image {
    width: 100%;
    height: 153px;
}
</style>
